/*
 * @(#)DataHandlerMethod.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.macro.method.component;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.nhncorp.lucy.common.data.DataHandler;
import com.nhncorp.lucy.common.data.DataHandlerFactory;

import com.nhncorp.usf.core.util.StringUtil;

import freemarker.template.TemplateMethodModel;
import freemarker.template.TemplateModelException;

/**
 * @author Web Platform Development Team
 */
public class DataHandlerMethod implements TemplateMethodModel {
    Log log = LogFactory.getLog(DataHandlerMethod.class);

    /**
     * @param args the arguments
     * @return the data handler value
     * @throws TemplateModelException the TemplateModelException
     */
    @SuppressWarnings("unchecked")
	public Object exec(List args) throws TemplateModelException {

        if (args.size() != 1) {
            throw new IllegalArgumentException();
        }

        String path = (String)args.get(0);

        if (StringUtil.isEmpty(path, false)) {
            throw new IllegalArgumentException("Path must not be empty.");
        }

        DataHandler dataHandler = DataHandlerFactory.getDataHandler();
        String dataHandlerValue = dataHandler.get(path, "");
        log.debug("dataHandlerValue=" + dataHandlerValue);

        return dataHandlerValue;
    }

}
